﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Project
{
    public partial class BKxiu : Form
    {
        public int id;
        public BKxiu()
        {
            InitializeComponent();
        }

        private void BKxiu_Load(object sender, EventArgs e)
        {
         
            s();
        }
        public void s() 
        {
            string sql = "select * from CetaeInfo ";
            SqlDataReader reader = DBHelper.SelectMore(sql);
            
            if(reader.Read())
            {
                this.textBox1.Text = reader["CeName"].ToString();
                this.textBox2.Text = reader["CeSex"].ToString();
                this.textBox3.Text = reader["CeHao"].ToString();
                this.textBox4.Text = reader["CePhone"].ToString();
                this.textBox5.Text = reader["CeAddress"].ToString();
            }
            reader.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bkx();
        }
        public void bkx() 
        {
            string name = this.textBox1.Text;
            string sex = this.textBox2.Text;
            string zjh = this.textBox3.Text;
            string phone = this.textBox4.Text;
            string address = this.textBox5.Text;

            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(address) || string.IsNullOrEmpty(phone))
            {
                MessageBox.Show("请填写完整");
            }
            string sqls = string.Format("update CetaeInfo set CeName='{0}',CeSex='{1}',CeHao='{2}',CePhone='{3}',CeAddress='{4}' where CeFangHao ={5}", name, sex, zjh, phone, address, id);
            int result = DBHelper.ExecuteUpdate(sqls);
            if (result > 0)
            {
                MessageBox.Show("修改成功");
            }
            else 
            {
                MessageBox.Show("修改失败");
            }
        }

    }
}
